'use strict';
const chalk = require('chalk');
const express = require('./express');

module.exports.init = function init(callback){
	if(callback){
		var app = null,
		db = null,
		config = {
			db : {
				uri : 'i am uri'
			},
			meanjs : {
				version : '1'
			},
			port : '3000',
			host : 'localhost',
			app : {
				title : 'i am title'
			}
		}

		app = express.init(db);

		callback(app, db, config);
	}
}


module.exports.start = function start(callback){
	var _this = this;

	_this.init(function(app, db, config){
		app.listen(config.port, config.host, function(){
			var server = (process.env.NODE_ENV === 'secure' ? 'https://' : 'http://') + config.host + ':' + config.port;
			console.log('--');
    		console.log(chalk.green(config.app.title));
    		console.log();
    		console.log(chalk.green('Environment:     ' + process.env.NODE_ENV));
    		console.log(chalk.green('Server:          ' + server));
    		console.log(chalk.green('Database:        ' + config.db.uri));
    		console.log(chalk.green('App version:     ' + config.meanjs.version));
    		if(callback){
    			callback(app, db, config);
   			}
		});
	});
};
